//
//  ActivityCenterViewController.m
//  WuLi
//
//  Created by Gollum on 16/9/3.
//  Copyright © 2016年 Gollum. All rights reserved.
//






#import "ActivityCenterViewController.h"
#import "ActivityCenterTableViewCell.h"
#import "ActivityCenterDetailViewController.h"
#import "NetworkTool.h"
#import "RankModel.h"
#import "RankData.h"
#import "RankAttached.h"
#import "RankNewscoverinfo.h"
#import "RankNewsimageinfolist.h"
#import "RankParamap.h"
#import "DKNightVersion.h"

#define kActivityCenterCellReuse @"ActivityCenter"
@interface ActivityCenterViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic,strong)RankModel *activityData;
//容器
@property (nonatomic,strong)NSMutableArray *containerArray;
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@end


@implementation ActivityCenterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self handleData];
    // Do any additional setup after loading the view from its nib.
    self.view.dk_backgroundColorPicker = DKColorWithColors([UIColor whiteColor], [UIColor grayColor]);
    _containerArray = [NSMutableArray array];
    _tableView.rowHeight = 230;
    _tableView.bounces = NO;
    _tableView.dk_backgroundColorPicker = DKColorWithColors([UIColor whiteColor], [UIColor grayColor]);
    
    [_tableView registerNib:[UINib nibWithNibName:@"ActivityCenterTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:kActivityCenterCellReuse];
    
}

- (void)handleData{
    
    NSString *urlString = @"http://api.5wuli.com/v1/activity/list";
    
    NSDictionary *header = @{@"User-Agent":@"Dalvik/2.1.0 (Linux; U; Android 5.0; ASUS_Z00ADB Build/LRX21V) Wuli/2.3.1 (agent:s;channel:wandoujia;credential:e1MyMDEwMDAxMDF9LXsjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIzM1Nzg3MjA2MTcxNDM4M30teyMjIyMjIyMxNDcyMDAyMTMyOTYzLTJlZjRjNThjZDJ9QDE0NzExODgxOTgzODY=;deviceId:357872061714383;osTypeId:01;detailInfo:android;simTypeId:01;netTypeId:01;deviceTypeId:01;osVersion:5.0;idfa:null)", @"Host":@"api.5wuli.com"};
    
    [NetworkTool GET:urlString andBody:nil andHeader:header andResponse:JHJSON andSuccessBlock:^(id result) {
        
        //        NSLog(@"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++%@",result);
        _activityData = [RankModel modelWithDic:result];
        
        [self.containerArray addObject:_activityData];
        
        [self.tableView reloadData];
        
    } andFailureBlock:^(NSError *error) {
        
    }];
    
}


- (IBAction)handleBack:(id)sender {
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return _activityData.data.count;

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    ActivityCenterTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kActivityCenterCellReuse];

    cell.title.text = _activityData.data[indexPath.row].title;
    NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:_activityData.data[indexPath.row].newsImageInfoList[0].url]];
    cell.mainImage.image = [UIImage imageWithData:data];
    
    return  cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    ActivityCenterDetailViewController *activityDetail = [[ActivityCenterDetailViewController alloc] init];
    
    //模态传值
    activityDetail.detailLinkStr = _activityData.data[indexPath.row].originLink;
    NSLog(@"传值之前:%@",activityDetail.detailLinkStr);

    [self presentViewController:activityDetail animated:YES completion:^{
        
        
        
    }];

}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];


}


@end
